<HTML>
<HEAD>
<TITLE>[Chapter 19] FontMetrics</TITLE>
<META NAME="author" CONTENT="John Zukowski">
<META NAME="date" CONTENT="Thu Jul 31 15:12:34 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java AWT">
<META NAME="title" CONTENT="Java AWT">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java AWT" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch19_24.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 19<br>java.awt Reference</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch19_26.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=refnamediv>
<H1>FontMetrics</H1>

<H2>Name</H2>

FontMetrics

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch19-REFSECT1-AUTOID.25"></A></h2>
</DIV>


<p>
<img align=middle src="./figs/fontmet.gif" alt="[Graphic: Figure from the text]" width=502 height=53 border=0>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-1">Description</A></h2>

<P CLASS=para>
The <tt CLASS=literal>FontMetrics</tt> class provides 
the means to calculate actual width and height of text if drawn on the 
screen. 

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-2">Class Definition</A></h2>

<DIV CLASS=screen>
<P>
<PRE>
public abstract class java.awt.FontMetrics
    extends java.lang.Object
    implements java.io.Serializable {
  
  // Variables
  protected Font font;
  
  // Constructors
  protected FontMetrics (Font font);
  
  // Instance Methods
  public int bytesWidth (byte data[], int offset, int length);
  public int charsWidth (char data[], int offset, int length);
  public int charWidth (char character);
  public int charWidth (int character);
  public int getAscent();
  public int getDescent();
  public Font getFont();
  public int getHeight();
  public int getLeading();
  public int getMaxAdvance();
  public int getMaxAscent();
  public int getMaxDecent();
  public int getMaxDescent();
  public int[] getWidths();
  public int stringWidth (String string);
  public String toString();
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-3">Variables</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-3.1">font</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-3.1.1">protected Font font</A></h4>

<P CLASS=para>
The <tt CLASS=literal>Font</tt> object whose metrics 
are represented by this object. 

</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-4">Constructors</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-4.1">FontMetrics</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-4.1.1">protected FontMetrics (Font font)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>font</I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>Font</tt> 
object whose metrics you want. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Constructs a platform specific <tt CLASS=literal>FontMetrics</tt> 
object for the given <tt CLASS=literal>font</tt>. </DL>
</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5">Instance Methods</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.1">bytesWidth</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.1.1">public int bytesWidth (byte data[], int offset, int length)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>data[]</I><br>
<DD>

<P CLASS=para>
Array of characters to lookup. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>offset</I><br>
<DD>

<P CLASS=para>
Initial character position. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>length</I><br>
<DD>

<P CLASS=para>
Number of characters to lookup. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
Advance width of characters in the array, starting with <tt CLASS=literal>offset</tt> 
and ending with <tt CLASS=literal>offset+length</tt>, 
in pixels. 

<p>
<DT CLASS=varlistentry>Throws<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>ArrayIndexOutOfBoundsException</I><br>
<DD>

<P CLASS=para>
If 
<tt CLASS=literal>offset</tt> or <tt CLASS=literal>length</tt> 
is invalid. </DL>
</DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.2">charsWidth</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.2.1">public int charsWidth (char data[], int offset, int length)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>data[]</I><br>
<DD>

<P CLASS=para>
Array of characters to lookup. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>offset</I><br>
<DD>

<P CLASS=para>
Initial character position. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>length</I><br>
<DD>

<P CLASS=para>
Number of characters to lookup. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
Advance width of characters in the array, starting with <tt CLASS=literal>offset</tt> 
and ending with <tt CLASS=literal>offset+length-1</tt>, 
in pixels. 

<p>
<DT CLASS=varlistentry>Throws<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>ArrayIndexOutOfBoundsException</I><br>
<DD>

<P CLASS=para>
If 
<tt CLASS=literal>offset</tt> or <tt CLASS=literal>length</tt> 
is invalid. </DL>
</DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.3">charWidth</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.3.1">public int charWidth (char character)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>character</I><br>
<DD>

<P CLASS=para>
character to lookup </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
Advanced pixel width of character. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.3.2">public int charWidth (int character)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>character</I><br>
<DD>

<P CLASS=para>
int value of character to lookup </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
Advanced pixel width of character. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.4">getAscent</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.4.1">public int getAscent()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
Amount of space above the baseline required for the tallest character in 
the font. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.5">getDescent</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.5.1">public int getDescent()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
Amount of space below the baseline required for the lowest descender (e.g., 
the tail on "p") in the font. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.6">getFont</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.6.1">public Font getFont()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>Font</tt> whose metrics are 
represented by this object. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.7">getHeight</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.7.1">public int getHeight()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The sum of <tt CLASS=literal>getDescent()</tt>, <tt CLASS=literal>getAscent()</tt>, 
and <tt CLASS=literal>getLeading()</tt>; recommended 
total space between baselines. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.8">getLeading</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.8.1">public int getLeading()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
Retrieves recommended amount of space between lines of text. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.9">getMaxAdvance</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.9.1">public int getMaxAdvance()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
Retrieves advance pixel width of widest character in the font. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.10">getMaxAscent</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.10.1">public int getMaxAscent()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
Retrieves maximum amount of space above the baseline required for the tallest 
character within the font's <tt CLASS=literal>FontMetrics</tt>. 
May differ from <tt CLASS=literal>getAscent()</tt> 
for characters with diacritical marks. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.11">getMaxDecent</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.11.1">public int getMaxDecent()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
Retrieves the maximum amount of space below the baseline required for the 
deepest character for the font. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
A misspelling of <tt CLASS=literal>getMaxDescent()</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.12">getMaxDescent</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.12.1">public int getMaxDescent()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
Retrieves the maximum amount of space below the baseline required for the 
deepest character for the font. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.13">getWidths</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.13.1">public int[] getWidths()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
255 element array of character widths. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Retrieves an integer array of the advance widths of the first 255 characters 
in the <tt CLASS=literal>FontMetrics</tt>' font. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.14">stringWidth</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.14.1">public int stringWidth (String string)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>string</I><br>
<DD>

<P CLASS=para>
Character string to lookup. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
Advance pixel width of <tt CLASS=literal>string</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.15">toString</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-5.15.1">public String toString()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A string representation of the <tt CLASS=literal>FontMetrics</tt> 
object. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry>Overrides <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>Object.toString()</tt> </DL>
</DL>
</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JAWT-CH-19-REF-FONTMETRICS-SECT-6">See Also</A></h2>

<P CLASS=para>
<tt CLASS=literal>Font, Object, String</tt> 

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch19_24.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch19_26.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>Font</td>
<td width=171 align=center valign=top><a href="index/idx_a.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>Frame</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
